package com.data.practice.array;

import org.junit.Test;

import java.io.*;

/**
 * Create with Intellij IDEA.
 * Description：
 * User:Zero
 * Date:2021/4/15
 * Time:17:28
 */
public class WriteArrayToDisk {
    /**
    *@Description:将数组写入磁盘
    */
    @Test
    public void test1() throws IOException {
        FileWriter fileWriter = new FileWriter("D:/array.text");
        int arr[]={1,2,3,4,5};
        for (int i = 0; i < arr.length; i++) {
            fileWriter.write(arr[i]+"\t");
        }
        fileWriter.close();
    }
    /**
    *@Description:读取文件中的数组
    */
    @Test
    public void test2() throws IOException {
        int[] ints = new int[5];
        FileReader fileReader = new FileReader("D:/array.text");
        for (int i = 0; i <ints.length; i++) {
               ints[i]=fileReader.read();
        }

        for (int rows:ints){
            System.out.print(rows);
        }
    }
}
